/**
 * minimalizaSidebar - Directive for minimalize sidebar
*/
class minimalizaSidebar{
    constructor() {
        this.restrict   = 'E';
        this.template   = '<div class="spin-icon"><i class="fa fa-bars"></i></div>';
        this.replace    = true;
        this.transclude = true;
    }

    link(scope, element, attrs, controller) {
        element.on('click', this.minimalize)
    }

    minimalize() {

        var body     = angular.element('body'),
            sideMenu = angular.element('#side-menu');

        body.toggleClass("mini-navbar");
        if (!body.hasClass('mini-navbar') || body.hasClass('body-small')) {
            // Hide menu in order to smoothly turn on when maximize menu
            sideMenu.css({'display': 'none'});
            // For smoothly turn on menu
            setTimeout(function () {
                    sideMenu.css({'display': 'block'});
            }, 300);
        } else if (body.hasClass('fixed-sidebar')){
            sideMenu.css({'display': 'none'});
            setTimeout(function () {
                    sideMenu.css({'display': 'block'});
            }, 300);
        } else {
            // Remove all inline style from jquery fadeIn function to reset menu state
            sideMenu.removeAttr('style');
        }
    }
}

export default minimalizaSidebar;